import java.sql.SQLOutput;
import java.util.*;
import java.util.*;
public class Test{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while(t-- > 0){
            int n = in.nextInt(), k = in.nextInt();
            int[][] a = new int[n][2];
            for(int i=0; i<n; i++) a[i][0] = in.nextInt();
            for(int i=0; i<n; i++) a[i][1] = in.nextInt();
            Arrays.sort(a, (x, y) -> x[0] - y[0]);
            PriorityQueue<Integer> que = new PriorityQueue<>((x,y)->y-x);
            long s = 0;
            for(int i=0; i<k; i++){
                que.offer(a[i][1]);
                s += a[i][1];
            }
            long ans = s * a[k-1][0];
            for(int i=k; i<n; i++){
                if(que.peek() > a[i][1]){
                    s -= que.poll();
                    s += a[i][1];
                    que.offer(a[i][1]);
                }
                ans = Math.min(ans, s * a[i][0]);
            }
            System.out.println(ans);
        }
    }
}